package blaha.genalg.graphgen;

import java.util.Date;
import java.util.Random;

import org.apache.log4j.Logger;

import blaha.genalg.beans.Board;
import blaha.genalg.beans.Point;
import blaha.genalg.methods.ReadAllProperties;
import blaha.logging.Log;

public class PlacePointsToCreateFirstLevel {
	
	private static final Logger log = Log.getLoggerMoje();

	public PlacePointsToCreateFirstLevel() {
		// some init here maybe
	}

	static Random rand;

	public Board Create(Board board, ReadAllProperties settings) {
		float radius = settings.radiusCircle;
		// GenerateAxes ga = new GenerateAxes(settings.xBoard,
		// settings.yBoard);
		rand = new Random(new Date().getTime());
		//int count = 0;
		int x = 0;
		int y = 0;
		final float setProb = settings.innerCirclePutPointProbability;
		final int  setX = settings.xBoard;
		final int  setY = settings.yBoard;
		final int  setMaxPoints = settings.points;
		for (int u=0;u<setMaxPoints;u++) {

			if (rand.nextFloat() < setProb) {

				// vne kruhu
				do {
					// vygenerovat x,y, dostat vzdalenost od stredu
					x = rand.nextInt(setX);
					y = rand.nextInt(setY);
					x -= setX / 2; // middle
					y -= setY / 2; // middle
				} while (radius < Math.sqrt(x * x + y * y));

				// add good generated point
				Point pp = new Point(u);
				pp.setX(x);
				pp.setY(y);
				pp.centre = true;
				board.addPoint2Map(pp);

			} else {// bude mimo kruh
				// generuj pomoci ga x a y dokud nebudou vne
				do {
					// vygenerovat x,y, dostat vzdalenost od stredu
					
					x = rand.nextInt(setX);
					y = rand.nextInt(setY);
					x -= setX / 2; // middle
					y -= setY / 2; // middle
				} while (radius > Math.sqrt(x * x + y * y));

				Point pp = new Point(u);
				pp.setX(x);
				pp.setY(y);
				board.addPoint2Map(pp);

			}




		}

		return board;
	}

}
